package ar.pmt.gwt.client.recurso.store;

import ar.pmt.vista.beans.RecursoBean;

import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourcePasswordField;
import com.smartgwt.client.data.fields.DataSourceTextField;
import com.smartgwt.client.types.DSDataFormat;

public class RecursoDataSource extends DataSource {
	
	  private static RecursoDataSource instance = null;  
	   
	     public static RecursoDataSource getInstance(String url) {  
	         if (instance == null) {  
	             instance = new RecursoDataSource(new Integer(0), url);  
	         }  
	         return instance;  
	     } 
	     
	  public RecursoDataSource(Integer id, String url) {  
		  setID(id.toString());
		    
		  DataSourceIntegerField recursoIdField = new DataSourceIntegerField(RecursoBean.getIdID(), "Recurso ID");  
		  recursoIdField.setPrimaryKey(true);  
		  recursoIdField.setRequired(true); 
		  
		  DataSourceTextField nombreField = new DataSourceTextField(RecursoBean.getNombreID(), "Nombre", 125);
		  nombreField.setRequired(true);
		  DataSourceTextField apellidoField = new DataSourceTextField(RecursoBean.getApellidoID(), "Apellido", 125);
		  apellidoField.setRequired(true);
		  DataSourceTextField unicoIdField = new DataSourceTextField(RecursoBean.getUnicoIdID(), "User", 125);
	
		  DataSourceTextField emailField = new DataSourceTextField(RecursoBean.getEmailID(), "Email", 125);
		  DataSourceTextField telTrabajoField = new DataSourceTextField(RecursoBean.getTelTrabajoID(), "Tel. Trabajo", 125);
		  DataSourceTextField telCasaField = new DataSourceTextField(RecursoBean.getTelCasaID(), "Tel. Casa", 125);
		  DataSourceTextField smsField = new DataSourceTextField(RecursoBean.getSmsID(), "Sms", 125);
		  DataSourceTextField chatField = new DataSourceTextField(RecursoBean.getChatID(), "Chat", 125);
		  DataSourcePasswordField passField = new DataSourcePasswordField(RecursoBean.getPasswordID(), "Password", 125);
		  DataSourceTextField pais = new DataSourceTextField(RecursoBean.getPaisIsoID(), "Pais", 125);
		  DataSourceTextField idioma = new DataSourceTextField(RecursoBean.getIdiomaID(), "Idioma", 125);
		  DataSourceTextField gtm = new DataSourceTextField(RecursoBean.getGtmID(), "Idioma", 125);
		  
		  setFields(recursoIdField, nombreField, apellidoField, unicoIdField, emailField, telTrabajoField, telCasaField, smsField, chatField,
				    passField, pais, idioma, gtm);
		  
		  
		  setDataURL(url);
		  setDataFormat(DSDataFormat.JSON);
	  }

	  
}
